<template>
	<sw-form-frame v-model="visible" title="标签树" width="560" :type="formType" :loading="btnLoading" footer @submit="handleSubmitForm()">
		<el-form ref="form" size="medium" :model="formData" :rules="formRules" label-width="96px" v-loading="loading">
			<el-form-item label="上级标签树" prop="pid">
				<sw-tree-select v-model="formData.pid" :list="labelTreeData" v-bind="treeSelectConfig" :disabled="isDisabled"></sw-tree-select>
			</el-form-item>
			<el-form-item label="标签树名称" prop="name">
				<el-input v-model="formData.name"></el-input>
			</el-form-item>
			<el-form-item label="标签树描述">
				<el-input type="textarea" v-model="formData.content"></el-input>
			</el-form-item>
			<el-form-item label="排序">
				<el-input-number v-model="formData.sort" controls-position="right" :min="1" :max="999"></el-input-number>
			</el-form-item>
		</el-form>
	</sw-form-frame>
</template>

<script>
import lodash from 'lodash';
import formMixins from '@/mixins/formMixins';
import { labelTreeDetail, addedLabelTree } from '@/api/data/tbSysLabelTree';
export default {
	mixins: [formMixins],
	props: {
		list: { type: Array, default: () => [] }
	},
	data() {
		return {
			formName: '标签',
			formRules: {
				pid: [{ required: true, message: '请选择上级标签', trigger: 'change' }],
				name: [{ required: true, message: '请输入标签树名称', trigger: 'blur' }],
				del: [{ required: true, message: '请选择标签树类型', trigger: 'change' }]
			},
			treeSelectConfig: {
				filterable: true,
				placeholder: '选择标签',
				style: { width: '100%' },
				defaultProps: { label: 'name' }
			},
			treeSelectData: []
		};
	},
	computed: {
		isDisabled() {
			return this.isSub;
		},
		detailData() {
			return eval(labelTreeDetail);
		},
		callFunction() {
			return eval(addedLabelTree);
		},
		submitParams() {
			let params = { ...this.formData };
			if (this.isSub) delete params.id;
			return params;
		},
		labelTreeData() {
			return [{ id: '0', name: '顶级标签树', children: this.list }];
		}
	}
};
</script>
